import axios from '@/utils/request'
import {ITEMTYPE} from '@/pages/knowledge copy/type/knowledge'
import Item from 'antd/lib/list/Item'
//获取知识小测页面数据

export const getKnowledgeList = async (page:number,pageSize:number,title?:string,status?:string) => {
       return await axios.get('/api/knowledge',{
        params:{
            page:page,
            pageSize:pageSize,
            title:title,
            status:status
        }
    })
}


//删除数据
export const deleteKnowledgeList = async (id:string ) => {
    return await axios.delete(`/api/knowledge/${id}`)
}

//新建数据
export const crateData = async (values:ITEMTYPE) => {
    return await axios.post('/api/knowledge/book',{
        title:values.title,
        summary:values.summary,
        cover:values.cover,
        isCommentable:values.isCommentable
    })

}

//更新数据
export const editData = async (id:string,data:ITEMTYPE) => {
    return await axios.patch(`/api/knowledge/${id}`,{
        title:data.title,
        summary:data.summary
    })

}



export const getKnow_editor = async (id: string) => {
    return await axios.get(`/api/knowledge/${id}`)
}

export const getKnow_view = async (id: string) => {
    return await axios.post('/api/view', { url: `/knowledge/editor/${id}` })
}

//保存
export const getEditore = async (content?: string, html?: string, order?: number, parentId?: string, title?: string, toc?: string) => {
    return await axios.post('/api/knowledge/chapter',
        [
            {
                content: content,
                html: html,
                order: order,
                parentId: parentId,
                title: title,
                toc: toc,
            }
        ]
    )
}

//删除
export const getDelete = async(id:string)=>{
    return await axios.delete(`/api/knowledge/${id}`);
}

//发布线上
export const publish = async (id:string , status:string) => {
    return await axios.patch(`/api/knowledge/${id}`,{status:status})

}